//package com.wxy.demo.advice;
//
//import cn.hutool.json.JSONUtil;
//import com.wxy.demo.core.ApiResponse;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.converter.StringHttpMessageConverter;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//@Slf4j
//@RestControllerAdvice
////@RestControllerAdvice(basePackages = "com.wxy.demo")
//public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
//
//    @Override
//    public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
//        return true;
//    }
//
//    @Override
//    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
//        log.info("原始数据：{}", body);
//        if (body instanceof ApiResponse) {
//            return body;
//        }
//        if (returnType.getParameterType() == ResponseEntity.class) {
//            return body;
//        }
//        if (selectedConverterType == StringHttpMessageConverter.class) {
//            response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
//            return JSONUtil.toJsonStr(ApiResponse.ok(body));
//        }
//        return ApiResponse.ok(body);
//    }
//}
//
